
const baseUrl = "http://localhost:8806/";  //测试请求地址
const requestAll = (path, data={}, method) => {
  return new Promise((resolve, reject) => {
      let url = baseUrl + path;
      wx.request({
          url: url,
          data: data,
          method: method,
          success: (res => {
            console.log(res)
              if (res.statusCode === 200 && res.data.code === 200000) {
                  //200: 服务端业务处理正常结束
                  resolve(res.data)
              } else {
                wx.showToast({
                  title: res.data.message,
                  icon:'none',
                  duration: 1000
                })
                  reject(res.data)
              }
          }),
          fail: (res => {
              reject(res)
          })
      })
  })
}
const get = (path, data) => {
  return requestAll(path, data, 'GET')
}
const post = (path, data) => {
  return requestAll(path, data, 'POST')
}
const put = (path, data) => {
  return requestAll(path, data, 'PUT')
}
const request = {
  get,
  post,
  put
}

export default request;